﻿package inherit.button
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
		
	public class FrameButton extends MovieClip
	{
		protected var frameVOMap:Object;
		
		public function FrameButton(): void
		{
			frameVOMap = new Object;
		}
		
		public function setRollOver(startFrame:Object, endFrame:int): void
		{
			setOption(MouseEvent.ROLL_OVER, startFrame, endFrame);
		}
		
		public function setRollOut(startFrame:Object, endFrame:int): void
		{
			setOption(MouseEvent.ROLL_OUT, startFrame, endFrame);
		}
		
		public function setClick(startFrame:Object, endFrame:int): void
		{
			setOption(MouseEvent.CLICK, startFrame, endFrame);
		}
		
		private function setOption(eventType:String,startFrame:Object, endFrame:int ): void
		{
			if(!frameVOMap[eventType]) frameVOMap[eventType] = { startFrame:startFrame, endFrame:endFrame }//new FrameVO(new MouseEvent(eventType), startFrame, endFrame);
			if(!this.hasEventListener(eventType)) this.addEventListener(eventType, frameHandler);
			setChildOption(frameVOMap[eventType]);
		}
		
		/* templete method addFrameScript */
		protected function setChildOption(frameVO:Object): void 
		{
			this.addFrameScript(frameVO.endFrame, stop);
		}
		
		private function frameHandler(e:MouseEvent): void
		{
			setFrameVO(frameVOMap[e.type]);
		}
		
		private function setFrameVO(frameVO:Object): void
		{
			this.gotoAndPlay(frameVO.startFrame);
		}
		
		
	}//c
}